<template>
  <div>
    <el-table
      :data="specsList"
      style="width: 100%"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="规格编号"> </el-table-column>
      <el-table-column prop="specsname" label="规格名称"> </el-table-column>
      <el-table-column label="规格属性">
        <template slot-scope="scope">
          <div>
            <el-tag v-for="(item, index) in scope.row.attrs" :key="index">{{
              item
            }}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="success" v-if="scope.row.status == 1"
              >启 用</el-button
            >
            <el-button type="danger" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="primary" plain @click="edit(scope.row.id)"
              >编 辑</el-button
            >
            <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination background layout="prev, pager, next" :total="specsTotal" :page-size="specsSize" @current-change="change">
    </el-pagination>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { successAlert, warningAlert } from "../../../util/alert.js";
import { specsDel } from "../../../request/api";
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      specsList: "specs/list",
      specsTotal: "specs/total",
      specsSize: "specs/size",
    }),
  },
  methods: {
    ...mapActions({
      reqSpecsList: "specs/reqChangeList",
      reqSpecsTotal: "specs/reqChangeTotal",
      reqSpecsPage: "specs/reqChangePage",
    }),
    // 封装版本删除
    del(id) {
      specsDel({ id: id }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          this.reqSpecsList();
          this.reqSpecsTotal();
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
    // 编辑
    edit(id) {
      this.$emit("edit", id);
    },
    //当页码发生变化
    change(num) {
      this.reqSpecsPage(num);
    },
  },
  mounted() {
    this.reqSpecsPage(1);
    this.reqSpecsTotal();
  },
};
</script>
<style scoped>
</style>